package pl.edu.mimuw.irs.core.model.design.net.refinement;

import java.io.Serializable;

import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException.DesignCause;
import pl.edu.mimuw.irs.core.model.design.net.IRSNode;
import pl.edu.mimuw.irs.core.model.design.net.IRSPlace;
import pl.edu.mimuw.irs.core.model.design.net.IRSTransition;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-09
 */
public enum Refinement implements Serializable {

	SEQUENCE {
		public IRSAbstractChildren createFrom(IRSNode node) {
			return new IRSSequenceChildren(node);
		}
	},
	CONCURRENCY {
		public IRSAbstractChildren createFrom(IRSNode node) {
			if (node instanceof IRSPlace) return new IRSConcurrencyChildren((IRSPlace) node);
			throw new InternalDesignException(DesignCause.NOT_IRS_PLACE, "Creating " + CONCURRENCY, node);
		}
	},
	ALTERNATIVE {
		public IRSAbstractChildren createFrom(IRSNode node) {
			if (node instanceof IRSTransition) return new IRSAlternativeChildren((IRSTransition) node);
			throw new InternalDesignException(DesignCause.NOT_IRS_TRANSITION, "Creating " + ALTERNATIVE, node);
		}
	},
	ITERATION {
		public IRSAbstractChildren createFrom(IRSNode node) {
			if (node instanceof IRSPlace) return new IRSIterationChildren((IRSPlace) node);
			throw new InternalDesignException(DesignCause.NOT_IRS_PLACE, "Creating " + ITERATION, node);
		}
	},
	ACTIVITY {
		public IRSAbstractChildren createFrom(IRSNode node) {
			if (node instanceof IRSTransition) return new IRSActivityChildren((IRSTransition) node);
			throw new InternalDesignException(DesignCause.NOT_IRS_TRANSITION, "Creating " + ITERATION, node);
		}
	},
	NONE {
		public IRSAbstractChildren createFrom(IRSNode node) {
			return new IRSNoneChildren(node);
		}
	};
	
	private static final long serialVersionUID = -8115350799516809295L;

	// *** Attributes
	
	// *** Constructors
	
	// *** Methods
	
	@Override
	public String toString() {
		return super.toString().substring(0, 3);
	}

	/**
	 * Creates IRSChildren object in this refinement pattern for the given {@link IRSPlace}.
	 * @param irsPlace
	 * @return
	 */
	public abstract IRSAbstractChildren createFrom(IRSNode irsNode);
}
